﻿using System;
using System.Windows.Browser;

namespace jLight.Extensions
{
    public static class jQueryExtensionUtils
    {
        /// <summary>
        /// A generic iterator function, which can be used to seamlessly iterate over both objects and 
        /// arrays. Arrays and array-like objects with a length property (such as a function's arguments 
        /// object) are iterated by numeric index, from 0 to length-1. Other objects are iterated via their
        ///  named properties. 
        /// </summary>
        public static jQueryObject Each(this jQueryObject value, Func<object, object, object> function)
        {
            var jq = (ScriptObject) HtmlPage.Window.Eval("jQuery");
            return (ScriptObject)jq.Invoke("each", value.ScriptObject, jQueryFunction.CreateCallback2(function));
            //return (string.Format("$.each({0},{1})", value,  );
        }         
    }
}